<?php

namespace app\api\controller;

use app\api\logic\WebhookLogic;
use app\BaseController;//测试专用
use  app\common\controller\DBase;
use think\facade\Db;
use app\api\logic\ApiOrderLogic;
use app\order\logic\OrderLogic;
use Throwable;

class ApiOrder extends DBase
{
    /**
     * 模型
     * @var object
     * @phpstan-var ApiAdvaccountModel
     */

    public function initialize(): void
    {
        parent::initialize();
    }

    /**
     * 获取list
     * @throws Throwable
     */
    public function ApiOrderAddTag()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->ApiOrderAddTag($params);
    }

    /**
     * 获取list
     * @throws Throwable
     */
    public function ApiOrderList()
    {
        $params     = $this->request->get();
        return (new ApiOrderLogic())->ApiOrderList($params);
    }

    /**
     * 订单详情
     * @throws Throwable
     */
    public function ApiOrderInfo()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->ApiOrderInfo($params);
    }

    /**
     * 获取list
     * @throws Throwable
     */
    public function ApiOrderListTemporary()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->ApiOrderListTemporary($params);
    }
    
    /**
     * @desc   手动发货
     * @date   2024-07-09
     */
    public function ManualShipping($data=[]){
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->ManualShippings($params);
    }

    /**
     * @desc   创建事件
     * https://shopify.fan-zhou.com/api/ApiOrder/CreateEvent?order_id=6496163070263&shop_id=23&status=confirmed
     * @date   2024-07-09
     */
    public function CreateEvent($data=[]){
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->CreateEvent($params);
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 整理每日订单统计
     * @author zhangheng
     */
    public function OrderReportDaily($params = [])
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->OrderReportDaily($params);
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 整理每日SKU统计
     * @author zhangheng
     */
    public function OrderReportDailySku($params = [])
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->OrderReportDailySku($params);
    }
    
    /**
    * @desc    创建webhook
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function CreateWebhook()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->CreateWebhook($params);
    }
    
    /**
    * @desc    创建产品webhook
    * @date    2024/11/22
    * @author  zhangheng
    */
    public function CreateProductWebhook()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->CreateProductWebhook($params);
    }
    
    /**
    * @desc    webhook列表
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function WebhookList()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->WebhookList($params);
    }
    /**
    * @desc    客户行为日志
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function CustomerBehaviorLog()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->CustomerBehaviorLog($params);
    }
    /**
    * @desc    辅助插件-客户行为日志
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function PlugCustomerBehaviorLog()
    {
        $params     = $this->request->get();
        return (new ApiOrderLogic())->PlugCustomerBehaviorLog($params);
    }
    /**
    * @desc    预先匹配规则
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function customerj_handle()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->customerj_handle($params);
    }

    /**
    * @desc    查找metafields
    * @date    2024/8/15
    * @author  zhangheng
    */
    public function SearchForMetafields()
    {
        $params     = $this->request->get();
        return (new ApiOrderLogic())->SearchForMetafields($params);
    } 
    
    /**
    * @desc    添加metafields
    * @date    2024/8/15
    * @author  zhangheng
    */
    public function AddMetafields()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->AddMetafields($params);
    }
    /**
    * @desc    AddMetafieldsAfterpay
    * @date    2024/8/15
    * @author  zhangheng
    */
    public function AddMetafieldsAfterpay()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->AddMetafieldsAfterpay($params);
    }
    
    //请求php命令
    public function RequestPHPCommand()
    {
        $scriptPath = '/www/wwwroot/shopify_new_back/think';  
        $command = '/www/server/php/73/bin/php ' . escapeshellarg($scriptPath) . ' purchaseConsummer';  
        ob_start();   
        passthru($command, $return_var);
        $output = ob_get_clean();  
        halt($output);
        
    }

    /**
     * 获取Shopline
     * @throws Throwable
     */
    public function ApiOrderListShopline()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->ApiOrderListShopline($params);
    }

    /**
     * 获取Shopline
     * @throws Throwable
     */
    public function orders_creates_consumer()
    {
        $params     = $this->request->post();
        $ApiOrderLogic = new WebhookLogic();
        $res        = $ApiOrderLogic->orders_creates_consumer($params);
        return $this->jsonMessage(200,true,'操作成功','');
    }


    /**
     * 实时汇率查询
     * @throws Throwable
     */
    public function RealTimeExchangeRateInquiry()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->RealTimeExchangeRateInquiry($params);
    }

    /**
     * 导出客户
     * @throws Throwable
     */
    public function export_customer()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->export_customer($params);
    }
    /**
     * webhook接收17track
     * @throws Throwable
     */
    public function webhooksTrack()
    {
        $data     = $this->request->post();
        $ApiOrderLogic = new ApiOrderLogic();
        $return = $ApiOrderLogic->webhooksTrack($data);
        return json(DefaultResponse(200, true, '操作成功', $return));
    }
    /**
     * webhook接收17track
     * @throws Throwable
     */
    public function webhooksTrack718()
    {
        $data     = $this->request->post();
        $ApiOrderLogic = new ApiOrderLogic();
        $return = $ApiOrderLogic->webhooksTrack718($data);
        return json(DefaultResponse(200, true, '操作成功', $return));
    }

    /**
     * 客户订阅
     * @throws Throwable
     */
    public function customersSubscribe()
    {
        $data     = $this->request->post();
        $ApiOrderLogic = new ApiOrderLogic();
        $return = $ApiOrderLogic->customersSubscribe($data);
        return json(DefaultResponse(200, true, '操作成功', $return));
    }


    /**
     * @desc   创建变体修改对象ID
     * @author xx
     * @date   2024-12-25
     */
    public function createCalculatedOrderId(){
        $params =  $this->request->post();
        $res    =  (new ApiOrderLogic())->createCalculatedOrderId($params);
        return $this->jsonMessage(200, true, "获取成功!", $res);
    }





    /**
     * @desc   获取varientId
     * @author xx
     * @date   2024-12-25
     */
    public function get_varient_id(){
        $params =  $this->request->post();
        $res    =  (new ApiOrderLogic())->get_varient_id($params);
        return $this->jsonMessage(200, true, "获取成功!", $res);
    }


    /**
     * @desc   获取lineItemId
     * @author xx
     * @date   2024-12-25
     */
    public function get_lineItemId(){
        $params =  $this->request->post();
        $res    =  (new ApiOrderLogic())->get_lineItemId($params);
        return $this->jsonMessage(200, true, "获取成功!", $res);
    }



    /**
     * @desc   添加新变体
     * @author xx
     * @date   2024-12-25
     */
    public function addCalculatedOrder(){
        $params =  $this->request->post();
        $res    =  (new ApiOrderLogic())->addCalculatedOrder($params);
        return $this->jsonMessage(200, true, "获取成功!", $res);
    }



    /**
     * @desc   添加折扣到变体
     * @author xx
     * @date   2024-12-25
     */
    public function addDiscountOrder(){
        $params =  $this->request->post();
        $res    =  (new ApiOrderLogic())->addDiscountOrder($params);
        return $this->jsonMessage(200, true, "获取成功!", $res);
    }


    /**
     * @desc   提交数据变更
     * @author xx
     * @date   2024-12-25
     */
    public function pushUpdateOrder(){
        $params =  $this->request->post();
        $res    =  (new ApiOrderLogic())->pushUpdateOrder($params);
        return $this->jsonMessage(200, true, "获取成功!", $res);
    }

    /**
     * @desc   提交数据变更生产
     * @author xx
     * @date   2024-12-25
     */
    public function pushUpdateOrderProduce(){
        $params =  $this->request->post();
        $res    =  (new ApiOrderLogic())->pushUpdateOrderProduce($params);
        return $this->jsonMessage(200, true, "获取成功!", $res);
    }
    /**
     * @desc   提交数据变更生产
     * @author xx
     * @date   2024-12-25
     */
    public function HualeiSystemApi(){
        $params =  $this->request->get();
        $res    =  (new OrderLogic())->HualeiSystemApi($params);
        return $this->jsonMessage(200, true, "获取成功!", $res);
    }

    public function ShopifyCreatesRefunds(){
        $params =  $this->request->get();

        // $params['order_id']订单ID;
        // $params['shop_id']店铺ID;
        // $params['amount']退款金额;
        // $params['currency']币种;
        $res    =  (new ApiOrderLogic())->ShopifyCreatesRefunds($params);
        halt($res);
    }

    /**
    * @desc    订单详情
    * @date    2025/03/06
    * @author  zhangheng
    */
    public function OrderDetails()
    {
        $params =  $this->request->get();
        // $params['order_id'] 订单id;
        return (new ApiOrderLogic())->OrderDetails($params);
    }

    /**
    * @desc    订单sku详情
    * @date    2025/03/06
    * @author  zhangheng
    */
    public function OrderSkuDetails()
    {
        $params =  $this->request->get();
        // $params['order_id'] 订单id;
        return (new ApiOrderLogic())->OrderSkuDetails($params);
    }
    
    /**
    * @desc    订单sku详情
    * @date    2025/03/06
    * @author  zhangheng
    */
    public function export_test()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->export_test($params);
    }

    /**
    * @desc    订单sku详情
    * @date    2025/03/06
    * @author  zhangheng
    */
    public function export_master()
    {
        $params     = $this->request->get();
        $ApiOrderLogic = new ApiOrderLogic();
        return $ApiOrderLogic->export_master($params);
    }










}
